
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>JavaScript设计模式 · tgor note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tgor">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="html相对路径与绝对路径.html" />
    
    
    <link rel="prev" href="../category/前端技术栈.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Me
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../category/微服务.html">
            
                <a href="../category/微服务.html">
            
                    
                    微服务
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Java-Spring/Feign.html">
            
                <a href="../Java-Spring/Feign.html">
            
                    
                    HTTP客户端Feign
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Java-其他库/限流.html">
            
                <a href="../Java-其他库/限流.html">
            
                    
                    限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    限流Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../Java-Spring/负载均衡.html">
            
                <a href="../Java-Spring/负载均衡.html">
            
                    
                    负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    负载均衡Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../Java-其他库/熔断Hystrix.html">
            
                <a href="../Java-其他库/熔断Hystrix.html">
            
                    
                    熔断Hystrix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html#本地缓存">
            
                    
                    本地缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    分布式缓存Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html">
            
                    
                    分布式事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html#事务消息">
            
                    
                    可靠事务消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../Java-Spring/业务监控.html">
            
                <a href="../Java-Spring/业务监控.html">
            
                    
                    业务监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.13" data-path="../Java-其他库/分布式定时作业.html">
            
                <a href="../Java-其他库/分布式定时作业.html">
            
                    
                    分布式作业调度ElasticJob
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.14" data-path="../Java-ORM/ORM.html">
            
                <a href="../Java-ORM/ORM.html">
            
                    
                    ORM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.15" data-path="../Java-其他库/分布式系统及CAP原理.html">
            
                <a href="../Java-其他库/分布式系统及CAP原理.html">
            
                    
                    分布式系统及CAP原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.16" data-path="../MQ/RabbitMQ笔记.html">
            
                <a href="../MQ/RabbitMQ笔记.html">
            
                    
                    消息驱动Rabbitmq
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../category/数据库.html">
            
                <a href="../category/数据库.html">
            
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../Mysql/经典数据库设计案例.html">
            
                <a href="../Mysql/经典数据库设计案例.html">
            
                    
                    mysql设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../Mysql/Mysql事务与锁.html">
            
                <a href="../Mysql/Mysql事务与锁.html">
            
                    
                    mysql事务与锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../Mysql/mysql数据类型.html">
            
                <a href="../Mysql/mysql数据类型.html">
            
                    
                    mysql数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../Mysql/mysql索引及查询.html">
            
                <a href="../Mysql/mysql索引及查询.html">
            
                    
                    mysql索引与查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../Mysql/mysql索引及查询.html">
            
                <a href="../Mysql/mysql索引及查询.html#查询语句设计准则">
            
                    
                    mysql查询语句设计准则
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../Mysql/mysql性能测试.html">
            
                <a href="../Mysql/mysql性能测试.html">
            
                    
                    mysql性能测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../Mysql/mysql主从同步与读写分离.html">
            
                <a href="../Mysql/mysql主从同步与读写分离.html">
            
                    
                    mysql主从同步与读写分离
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                <a href="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                    
                    Spring事务注解@Transactional
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../数据结构与算法/位运算应用实例.html">
            
                <a href="../数据结构与算法/位运算应用实例.html">
            
                    
                    位运算应用实例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="../Mongodb-Client/morphia-API汇总.html">
            
                <a href="../Mongodb-Client/morphia-API汇总.html">
            
                    
                    morphia API汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="../Mongodb-Client/mongo驱动连接.html">
            
                <a href="../Mongodb-Client/mongo驱动连接.html">
            
                    
                    mongodb驱动与连接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="../Mongodb/mongodb-ObjectId实践.html">
            
                <a href="../Mongodb/mongodb-ObjectId实践.html">
            
                    
                    mongodb ObjectId实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="../Mongodb/mongodb角色权限.html">
            
                <a href="../Mongodb/mongodb角色权限.html">
            
                    
                    mongodb角色权限
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../category/java并发.html">
            
                <a href="../category/java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#锁">
            
                    
                    Java并发之锁设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#synchronized">
            
                    
                    Java并发之synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantlock">
            
                    
                    Java Lock之ReentrantLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantreadwritelock">
            
                    
                    Java Lock之ReentrantReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html">
            
                    
                    Java Future
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#futuretask">
            
                    
                    Java Future之FutureTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#completablefuture">
            
                    
                    Java Future之CompletableFuture
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#forkjointask">
            
                    
                    Java Future之ForkJoinTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../Java-Base/Java之Thread.html">
            
                <a href="../Java-Base/Java之Thread.html">
            
                    
                    Java Thread
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../category/redis.html">
            
                <a href="../category/redis.html">
            
                    
                    Redis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#集群">
            
                    
                    Redis集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#消息订阅">
            
                    
                    Redis消息订阅
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#lua">
            
                    
                    Redis Lua脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#配置汇总">
            
                    
                    Redis配置汇总
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../category/运维.html">
            
                <a href="../category/运维.html">
            
                    
                    运维
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../运维/Linux常用操作汇总.html">
            
                <a href="../运维/Linux常用操作汇总.html">
            
                    
                    Linux常用操作汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../运维/阿里云笔记.html">
            
                <a href="../运维/阿里云笔记.html">
            
                    
                    阿里云笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../category/nginx.html">
            
                <a href="../category/nginx.html">
            
                    
                    Nginx
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html">
            
                    
                    Nginx基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    Nginx负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    Nginx限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html#六、其他">
            
                    
                    Nginx客户端辅助技巧
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../category/容器化.html">
            
                <a href="../category/容器化.html">
            
                    
                    容器化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html">
            
                    
                    Docker学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#基础操作">
            
                    
                    Docker基础操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#dockerfile">
            
                    
                    DockerFile
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../category/Web.html">
            
                <a href="../category/Web.html">
            
                    
                    Web
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../运维/Http入坑Https笔记.html">
            
                <a href="../运维/Http入坑Https笔记.html">
            
                    
                    Http入坑Https笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../Web/阿里云OSS.html">
            
                <a href="../Web/阿里云OSS.html">
            
                    
                    OSS
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../category/java基础.html">
            
                <a href="../category/java基础.html">
            
                    
                    Java基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#jvm">
            
                    
                    JVM基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#语法糖">
            
                    
                    Java语法糖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#数据结构">
            
                    
                    Java数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../Java-Base/Java8函数式编程.html">
            
                <a href="../Java-Base/Java8函数式编程.html">
            
                    
                    java8函数式编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../Java-Base/ArrayList源码分析.html">
            
                <a href="../Java-Base/ArrayList源码分析.html">
            
                    
                    JDK源码分析ArrayList
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../Java-Base/HashMap源码分析.html">
            
                <a href="../Java-Base/HashMap源码分析.html">
            
                    
                    JDK源码分析HashMap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../Java-Base/Java注解.html">
            
                <a href="../Java-Base/Java注解.html">
            
                    
                    Java注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../Java-Base/Timsort排序算法.html">
            
                <a href="../Java-Base/Timsort排序算法.html">
            
                    
                    Timsort排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../Java-Base/插入排序分析与Java实现.html">
            
                <a href="../Java-Base/插入排序分析与Java实现.html">
            
                    
                    插入排序分析与Java实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../category/工具与规范.html">
            
                <a href="../category/工具与规范.html">
            
                    
                    工具与规范
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../工具/Maven使用技巧汇总.html">
            
                <a href="../工具/Maven使用技巧汇总.html">
            
                    
                    Maven使用技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../编码规范/Java编码规范.html">
            
                <a href="../编码规范/Java编码规范.html">
            
                    
                    Java编码规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../category/OLAP.html">
            
                <a href="../category/OLAP.html">
            
                    
                    OLAP
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../数据处理/storm学习笔记.html">
            
                <a href="../数据处理/storm学习笔记.html">
            
                    
                    流式计算Storm学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../category/数据运营.html">
            
                <a href="../category/数据运营.html">
            
                    
                    数据运营
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../数据运营/增长黑客数据运营.html">
            
                <a href="../数据运营/增长黑客数据运营.html">
            
                    
                    增长黑客-数据运营
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../category/前端技术栈.html">
            
                <a href="../category/前端技术栈.html">
            
                    
                    前端技术栈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.14.1" data-path="JavaScript设计模式.html">
            
                <a href="JavaScript设计模式.html">
            
                    
                    JavaScript设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="html相对路径与绝对路径.html">
            
                <a href="html相对路径与绝对路径.html">
            
                    
                    Html相对路径与绝对路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="微信小程序学习笔记.html">
            
                <a href="微信小程序学习笔记.html">
            
                    
                    微信小程序学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../category/个人.html">
            
                <a href="../category/个人.html">
            
                    
                    个人
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../个人/简历.html">
            
                <a href="../个人/简历.html">
            
                    
                    简历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >JavaScript设计模式</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="javascript&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;">JavaScript&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;</h1>
<p>&#x6807;&#x7B7E;&#xFF1A;JavaScript </p>
<h2 id="&#x524D;">&#x524D;</h2>
<p>&#x5728;&#x5B66;&#x4E60;&#x4F7F;&#x7528;Javascript&#x4E4B;&#x524D;&#xFF0C;&#x6211;&#x7684;&#x7A0B;&#x5E8F;&#x733F;&#x751F;&#x6DAF;&#x91CC;&#x9762;&#x4EC5;&#x6709;&#x63A5;&#x89E6;&#x7684;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x662F;C#&#x8DDF;Java&#x2014;&#x2014;&#x5FFD;&#x7565;&#x5F53;&#x5E74;&#x5728;&#x5927;&#x5B66;&#x8865;&#x8003;&#x4E86;N&#x6B21;&#x7684;C&#x4E0E;VB&#x3002;</p>
<p>&#x4ECE;&#x9759;&#x6001;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#xFF0C;&#x8F6C;&#x5230;&#x52A8;&#x6001;&#x8BED;&#x8A00;JS&#xFF0C;&#x521A;&#x5F00;&#x59CB;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x9047;&#x5230;&#x4E0D;&#x5C11;&#x56F0;&#x96BE;&#x4E0E;&#x9519;&#x8BEF;&#x3002;&#x53EF;&#x80FD;&#x56E0;&#x4E3A;&#x5148;&#x5165;&#x4E3A;&#x4E3B;&#xFF0C;&#x5728;JS&#x7F16;&#x7A0B;&#x4E4B;&#x4E2D;&#xFF0C;&#x5F80;&#x5F80;&#x4E0D;&#x7531;&#x81EA;&#x4E3B;&#x5730;&#x4EE5;C#&#x7684;&#x903B;&#x8F91;&#x3001;&#x7F16;&#x7A0B;&#x601D;&#x8DEF;&#x3001;&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x8FDB;&#x884C;JS&#x5F00;&#x53D1;&#x3002;</p>
<p>&#x65F6;&#x95F4;&#x957F;&#x4E86;&#xFF0C;&#x6E10;&#x6E10;&#x53D1;&#x73B0;JS&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x5BF9;&#x4E8E;&#x524D;&#x7AEF;&#x5F00;&#x53D1;&#x7684;&#x91CD;&#x8981;&#x6027;&#xFF0C;&#x4F46;&#x5728;&#x5206;&#x4EAB;JS&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x4E4B;&#x524D;&#xFF0C;&#x5E0C;&#x671B;&#x9996;&#x5148;&#x5206;&#x4EAB;&#x51E0;&#x70B9;&#x4E2A;&#x4EBA;&#x89C9;&#x5F97;&#x5F88;&#x91CD;&#x8981;&#x7684;JS&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x57FA;&#x7840;&#x3002;&#x6709;&#x4E9B;&#x5730;&#x65B9;&#xFF0C;&#x53EF;&#x80FD;&#x7814;&#x7A76;&#x5F97;&#x4E5F;&#x4E0D;&#x662F;&#x5F88;&#x6DF1;&#x5165;&#xFF0C;&#x6709;&#x4EC0;&#x4E48;&#x9519;&#x8BEF;&#x7684;&#x8BDD;&#xFF0C;&#x671B;&#x6307;&#x6B63;&#x3002;</p>
<h2 id="&#x52A8;&#x6001;&#x7C7B;&#x578B;&#x8BED;&#x8A00;">&#x52A8;&#x6001;&#x7C7B;&#x578B;&#x8BED;&#x8A00;</h2>
<p>&#x9759;&#x6001;&#x7C7B;&#x578B;&#x8BED;&#x8A00;&#xFF0C;&#x5728;&#x7F16;&#x8BD1;&#x9636;&#x6BB5;&#xFF0C;&#x5C31;&#x9700;&#x8981;&#x786E;&#x5B9A;&#x53D8;&#x91CF;&#x7684;&#x7C7B;&#x578B;&#x3002;&#x4F46;&#x52A8;&#x6001;&#x7C7B;&#x578B;&#x8BED;&#x8A00;&#xFF0C;&#x53EA;&#x6709;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x65F6;&#xFF0C;&#x6839;&#x636E;&#x5F53;&#x65F6;&#x8BED;&#x8A00;&#x6267;&#x884C;&#x73AF;&#x5883;&#xFF0C;&#x53D8;&#x91CF;&#x624D;&#x4F1A;&#x8D4B;&#x4E88;&#x5176;&#x7C7B;&#x578B;&#x3002;</p>
<p>&#x6240;&#x4EE5;C#&#xFF0C;&#x4E0D;&#x80FD;&#x629B;&#x5F00;runtime&#x4E0E;&#x7F16;&#x8BD1;&#x5668;&#x5355;&#x72EC;&#x8FD0;&#x884C;&#xFF0C;Java&#x4E5F;&#x79BB;&#x4E0D;&#x5F00;JVM&#x3002;&#x540C;&#x65F6;&#x4E5F;&#x6709;&#x4E00;&#x5927;&#x5806;&#x95EE;&#x9898;&#x9700;&#x8981;&#x8003;&#x8651;&#x7684;&#xFF0C;&#x8DE8;&#x5E73;&#x53F0;&#x3001;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x3001;&#x53CD;&#x5C04;&#x3001;Ioc&#x3001;&#x63A5;&#x53E3;&#x7F16;&#x7A0B;&#x3001;&#x62BD;&#x8C61;&#x5316;&#x3001;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x7B49;&#x7B49;&#x4E00;&#x5927;&#x5806;&#x6982;&#x5FF5;&#x6280;&#x672F;&#x7684;&#x4EA7;&#x751F;&#xFF0C;&#x8FD8;&#x4E0D;&#x662F;&#x56E0;&#x4E3A;&#x9759;&#x6001;&#x8BED;&#x8A00;&#x7684;&#x5F3A;&#x7C7B;&#x578B;&#x7279;&#x6027;&#xFF0C;&#x9700;&#x8981;&#x66F4;&#x591A;&#x7684;&#x624B;&#x6BB5;&#x8BA9;&#x5176;&#x5F97;&#x5230;&#x7075;&#x6D3B;&#x591A;&#x6001;&#x7684;&#x7279;&#x6027;&#x3002;</p>
<pre><code class="lang-csharp">    <span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Main</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Function</span>(<span class="hljs-params"></span>)
        </span>{
            <span class="hljs-comment">//&#x5728;&#x7F16;&#x8BD1;&#x7684;&#x65F6;&#x5019;&#xFF0C;.net runtime&#x5FC5;&#x987B;&#x8981;&#x77E5;&#x9053;dog&#x662F;&#x4E00;&#x53EA;&#x72D7;</span>
            Dog dog = <span class="hljs-keyword">new</span> Dog();
            Console.WriteLine(dog.Name);
        }
    }
</code></pre>
<p>&#x4F46;&#xFF0C;JS&#x53EA;&#x9700;&#x8981;&#x4E2A;&#x6587;&#x672C;&#x7F16;&#x8F91;&#x5668;&#xFF0C;&#x6CA1;&#x6709;&#x7F16;&#x8BD1;&#x901A;&#x8FC7;&#x4E0D;&#x901A;&#x8FC7;&#x7684;&#x6982;&#x5FF5;&#xFF0C;&#x52A0;&#x8F7D;&#x4E86;&#x6D4F;&#x89C8;&#x5668;&#x5C31;&#x80FD;&#x8DD1;&#x3002;</p>
<pre><code class="lang-javascript">    <span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> a);<span class="hljs-comment">//number</span>

    a = <span class="hljs-string">&quot;a&quot;</span>;
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> a);<span class="hljs-comment">//string</span>
</code></pre>
<h2 id="&#x539F;&#x578B;&#x6A21;&#x5F0F;">&#x539F;&#x578B;&#x6A21;&#x5F0F;</h2>
<p>ECMAScript 5&#x4E4B;&#x524D;JS&#x662F;&#x6CA1;&#x6709;&#x7C7B;&#x7684;&#xFF0C;W3C&#x7684;&#x5927;&#x725B;&#x662F;&#x6709;&#x6240;&#x53D1;&#x73B0;&#x7684;&#xFF0C;&#x6240;&#x4EE5;ES6&#x4F1A;&#x65B0;&#x7684;&#x7C7B;&#x8BED;&#x6CD5;&#xFF0C;&#x4F46;&#x662F;&#x5404;&#x5927;&#x6D4F;&#x89C8;&#x5668;&#xFF08;IE&#xFF09;&#x7334;&#x5E74;&#x9A6C;&#x6708;&#x624D;&#x8DDF;&#x8FDB;&#x5C31;&#x4E0D;&#x5F97;&#x800C;&#x77E5;&#x4E86;&#x2014;&#x2014;&#x7EDD;&#x5BF9;&#x4E0D;&#x662F;&#x9488;&#x5BF9;IE&#x3002;</p>
<p>&#x5728;&#x9759;&#x6001;&#x7C7B;&#x578B;&#x8BED;&#x8A00;&#x5F00;&#x53D1;&#x4E2D;&#xFF0C;&#x7C7B;&#x662F;&#x4EFB;&#x610F;&#x5B9E;&#x4F53;&#x7684;&#x7ED3;&#x6784;&#xFF0C;&#x5F53;&#x9700;&#x8981;&#x8FD9;&#x4E2A;&#x5B9E;&#x4F53;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x7CFB;&#x7EDF;&#x4F9D;&#x7167;&#x8FD9;&#x4E2A;&#x7ED3;&#x6784;&#xFF0C;&#x201C;&#x753B;&#x201D;&#x51FA;&#x8FD9;&#x4E2A;==&#x5BF9;&#x8C61;==&#x3002;
&#x8B6C;&#x5982;&#xFF0C;&#x8981;&#x8BBE;&#x8BA1;&#x8F66;&#xFF0C;&#x9996;&#x5148;&#x662F;&#x8981;&#x8BBE;&#x8BA1;&#x7A3F;&#xFF0C;&#x8BBE;&#x8BA1;&#x7A3F;&#x5C31;&#x662F;&#x7C7B;&#xFF0C;&#x7136;&#x540E;&#x7167;&#x7740;&#x8BBE;&#x8BA1;&#x7A3F;&#x751F;&#x4EA7;&#x7684;&#x6BCF;&#x4E00;&#x53F0;&#x8F66;&#x5C31;&#x662F;&#x5177;&#x4F53;&#x7684;&#x5BF9;&#x8C61;&#x3002;
&#x6240;&#x4EE5;&#xFF0C;&#x9759;&#x6001;&#x7C7B;&#x578B;&#x8BED;&#x8A00;&#x5F53;&#x4E2D;&#xFF0C;&#x5F97;&#x5230;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x6700;&#x5173;&#x952E;&#x5C31;&#x662F;&#x5148;&#x6709;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x8BBE;&#x8BA1;&#x7A3F;&#xFF08;&#x7C7B;&#xFF09;&#xFF0C;&#x5C31;&#x662F;&#x77E5;&#x9053;&#x5B83;&#x7684;&#x7C7B;&#x578B;&#x3002;</p>
<p>&#x4F46;&#x662F;&#xFF0C;JS&#x4E0D;&#x4E00;&#x6837;&#x3002;
JS&#x662F;&#x4EE5;&#x539F;&#x578B;&#x6A21;&#x5F0F;&#x4F5C;&#x4E3A;&#x8BBE;&#x8BA1;&#x57FA;&#x7840;&#x3002;&#x5F97;&#x5230;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x4E4B;&#x524D;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x5173;&#x5FC3;&#x5BF9;&#x8C61;&#x5C5E;&#x4E8E;&#x4EC0;&#x4E48;&#x7C7B;&#x578B;&#xFF0C;&#x5B83;&#x7684;&#x8BBE;&#x8BA1;&#x7A3F;&#x662F;&#x600E;&#x4E48;&#x6837;&#x7684;&#xFF0C;JS&#x662F;&#x901A;&#x8FC7;&#x62F7;&#x8D1D;&#x4E00;&#x4E2A;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x800C;&#x83B7;&#x5F97;&#x5BF9;&#x8C61;&#x7684;&#x3002;</p>
<pre><code class="lang-javascript">    <span class="hljs-comment">//&#x5B9A;&#x4E49;&#x8D85;&#x4EBA;&#x662F;&#x8D85;&#x4EBA;&#xFF0C;&#x8D85;&#x4EBA;&#x53EF;&#x4EE5;&#x98DE;</span>
    <span class="hljs-keyword">var</span> superman = {
        name: <span class="hljs-string">&quot;superman&quot;</span>,
        fly: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.name + <span class="hljs-string">&quot; is flying&quot;</span>);
        }
    };
    superman.fly();<span class="hljs-comment">//superman is flying</span>

    <span class="hljs-comment">//&#x4E07;&#x4E00;&#xFF0C;&#x60F3;&#x8981;&#x4E2A;&#x59B9;&#x5B50;&#x5462;&#xFF0C;&#x641E;&#x4E2A;&#x5973;&#x8D85;&#x4EBA;&#x5982;&#x4F55;&#xFF1F;&#x5973;&#x8D85;&#x4EBA;&#x4E5F;&#x4F1A;&#x98DE;&#xFF1F;&#x8981;&#x4E0D;&#x5C31;&#x590D;&#x5236;&#x4E00;&#x4E2A;&#x8D85;&#x4EBA;&#x7684;&#x5BF9;&#x8C61;&#x5427;&#x3002;</span>
    <span class="hljs-comment">//&#x901A;&#x8FC7;Object.create&#x590D;&#x5236;&#x4E00;&#x4E2A;&#x8D85;&#x4EBA;&#xFF0C;&#x4F46;&#x5B9A;&#x4E49;&#x5B83;&#x662F;&#x5973;&#x8D85;&#x4EBA;&#x3002;</span>
    <span class="hljs-keyword">var</span> superwomen = <span class="hljs-built_in">Object</span>.create(superman);

    superwomen.name = <span class="hljs-string">&quot;superwomen&quot;</span>;
    superwomen.fly();<span class="hljs-comment">//superwomen is flying</span>

    <span class="hljs-comment">//DC&#x7684;&#x4E0D;&#x559C;&#x6B22;&#xFF0C;&#x6765;&#x4E2A;&#x6F2B;&#x5A01;&#x5427;&#xFF0C;&#x518D;&#x641E;&#x4E2A;&#x94A2;&#x94C1;&#x4FA0;&#xFF1F;&#x94A2;&#x94C1;&#x4FA0;&#x4E5F;&#x4F1A;&#x98DE;</span>
    <span class="hljs-keyword">var</span> ironman = <span class="hljs-built_in">Object</span>.create(superman);

    ironman.name = <span class="hljs-string">&quot;ironman&quot;</span>;
    ironman.fly();<span class="hljs-comment">//ironman is flying</span>
</code></pre>
<p>&#x5343;&#x4E07;&#x522B;&#x8BEF;&#x89E3;&#x4E86;superman&#x5C31;&#x662F;&#x7C7B;&#xFF0C;&#x800C;superwomen&#x3001;ironman&#x5C31;&#x662F;superman&#x5B9E;&#x4F8B;&#x5316;&#x5F97;&#x5230;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;superman&#x3001;superwomen&#x3001;ironman&#x90FD;&#x662F;&#x5BF9;&#x8C61;&#xFF0C;superwomen&#x3001;ironman&#x90FD;&#x662F;superman&#x5BF9;&#x8C61;&#x62F7;&#x8D1D;&#x7684;&#x7ED3;&#x679C;&#x3002;</p>
<h3 id="1&#x3001;&#x6240;&#x6709;&#x7684;&#x6570;&#x636E;&#x90FD;&#x662F;&#x5BF9;&#x8C61;">1&#x3001;&#x6240;&#x6709;&#x7684;&#x6570;&#x636E;&#x90FD;&#x662F;&#x5BF9;&#x8C61;</h3>
<p>&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#xFF0C;&#x901A;&#x8FC7;<code>var obj={}</code>&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#xFF0C;&#x5176;&#x7B49;&#x4EF7;&#x4E8E;<code>var obj=new Object()</code>&#x3002;Object&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#xFF0C;&#x4F46;&#x4E0D;&#x4EC5;&#x662F;Object&#x624D;&#x662F;&#x5BF9;&#x8C61;&#xFF0C;&#x6240;&#x6709;&#x7684;&#x6570;&#x636E;&#x90FD;&#x662F;&#x5BF9;&#x8C61;&#xFF0C;&#x5305;&#x62EC;Number&#x3001;Boolean&#x3001;String&#x3001;Function&#x3001;Object&#x3002;&#x8FD9;&#x662F;&#x539F;&#x578B;&#x6A21;&#x5F0F;&#x5F88;&#x91CD;&#x8981;&#x7684;&#x4E00;&#x6761;&#x539F;&#x5219;&#x3002;
&#x6B63;&#x662F;&#x8FD9;&#x4E00;&#x70B9;&#xFF0C;&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x5229;&#x7528;function&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#xFF1A;<code>function obj(){};</code>&#x3002;</p>
<p>&#x4E0D;&#x8FC7;&#x4E0E;<code>var obj=new Object()</code>&#x4E0D;&#x540C;&#xFF0C;function&#x5B9A;&#x4E49;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x5E26;&#x6784;&#x9020;&#x5668;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x901A;&#x8FC7;new&#x5173;&#x952E;&#x5B57;&#x8C03;&#x7528;&#x6784;&#x9020;&#x5668;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x5176;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x3002;&#x53C2;&#x8003;&#x4EE5;&#x4E0B;&#x4F8B;&#x5B50;&#x3002;</p>
<pre><code class="lang-javascript">    <span class="hljs-comment">//&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;</span>
    <span class="hljs-keyword">var</span> superman = {
        name: <span class="hljs-string">&quot;superman&quot;</span>,
        fly: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.name + <span class="hljs-string">&quot; is flying&quot;</span>);
        }
    };
    superman.fly();<span class="hljs-comment">//superman is flying</span>

    <span class="hljs-comment">//&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x540C;&#x65F6;&#x4E5F;&#x662F;&#x4E00;&#x4E2A;&#x5E26;&#x6784;&#x9020;&#x5668;&#x7684;&#x51FD;&#x6570;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">superman2</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">this</span>.name = <span class="hljs-string">&quot;superman&quot;</span>;
        <span class="hljs-keyword">this</span>.fly = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.name + <span class="hljs-string">&quot; is flying&quot;</span>);
        };
    };

    <span class="hljs-comment">//&#x9519;&#x8BEF;&#xFF1A;superman2&#x662F;&#x51FD;&#x6570;&#xFF0C;fly()&#x4E0D;&#x662F;&#x51FD;&#x6570;</span>
    superman2.fly();<span class="hljs-comment">//error:undefined is not a function</span>

    <span class="hljs-comment">//&#x9519;&#x8BEF;&#xFF1A;superman2()&#x662F;&#x8C03;&#x7528;&#x51FD;&#x6570;&#xFF0C;&#x4F46;&#x51FD;&#x6570;&#x6CA1;&#x6709;&#x8FD4;&#x56DE;&#x5E26;fly()&#x51FD;&#x6570;&#x7684;&#x5BF9;&#x8C61;</span>
    superman2().fly();<span class="hljs-comment">//error:Cannot read property &apos;fly&apos; of undefined</span>

    <span class="hljs-comment">//&#x6B63;&#x786E;&#xFF1A;new&#x4E0D;&#x662F;C#&#x5B9E;&#x4F8B;&#x5316;&#x5173;&#x952E;&#x5B57;&#xFF0C;new&#x662F;&#x8C03;&#x7528;superman2&#x7684;&#x6784;&#x9020;&#x5668;&#x5E76;&#x8FD4;&#x56DE;&#x5176;&#x5BF9;&#x8C61;</span>
    <span class="hljs-keyword">var</span> sm = <span class="hljs-keyword">new</span> superman2();
    sm.fly();<span class="hljs-comment">//superman is flying</span>
</code></pre>
<h3 id="2&#x3001;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x8BF7;&#x6C42;&#xFF0C;&#x4F1A;&#x4ECE;&#x5BF9;&#x8C61;&#x4F20;&#x9012;&#x5230;&#x5BF9;&#x8C61;&#x539F;&#x578B;">2&#x3001;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x8BF7;&#x6C42;&#xFF0C;&#x4F1A;&#x4ECE;&#x5BF9;&#x8C61;&#x4F20;&#x9012;&#x5230;&#x5BF9;&#x8C61;&#x539F;&#x578B;</h3>
<p>&#x5F53;&#x9700;&#x8981;&#x83B7;&#x5F97;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x65F6;&#xFF0C;&#x4F1A;&#x9996;&#x5148;&#x8BF7;&#x6C42;&#x5BF9;&#x8C61;&#x672C;&#x8EAB;&#xFF0C;&#x5982;&#x679C;&#xFF0C;&#x5BF9;&#x8C61;&#x672C;&#x8EAB;&#x6CA1;&#x6709;&#x5C5E;&#x6027;&#x53EF;&#x4EE5;&#x54CD;&#x5E94;&#xFF0C;&#x5219;&#x54CD;&#x5E94;&#x5176;&#x5BF9;&#x8C61;&#x539F;&#x578B;prototype&#xFF1B;&#x5982;&#x679C;prototype&#x4E5F;&#x6CA1;&#x6709;&#x5C5E;&#x6027;&#x53EF;&#x4EE5;&#x54CD;&#x5E94;&#xFF0C;&#x5219;&#x8FDB;&#x4E00;&#x6B65;&#x8BF7;&#x6C42;&#x539F;&#x578B;&#x7684;&#x539F;&#x578B;&#xFF0C;&#x4ECE;&#x800C;&#x5F62;&#x6210;&#x4E00;&#x6761;&#x539F;&#x578B;&#x94FE;&#x3002;&#x5F53;&#x7136;&#xFF0C;&#x539F;&#x578B;&#x94FE;&#x7684;&#x5C42;&#x7EA7;&#x4E0D;&#x80FD;&#x592A;&#x957F;&#xFF0C;&#x5177;&#x4F53;&#x957F;&#x5EA6;&#x6CA1;&#x6709;&#x7814;&#x7A76;&#x8FC7;&#xFF0C;&#x6211;&#x89C9;&#x5F97;3&#x7EA7;&#x4E5F;&#x5DEE;&#x4E0D;&#x591A;&#x4E86;&#x3002;</p>
<pre><code class="lang-javascript">    <span class="hljs-comment">//&#x5B9A;&#x4E49;&#x4EBA;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">human</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">this</span>.sexy = <span class="hljs-string">&quot;male&quot;</span>;
    };

    <span class="hljs-comment">//&#x5B9A;&#x4E49;&#x6240;&#x6709;&#x82F1;&#x96C4;&#x7684;&#x539F;&#x578B;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">heroBase</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">this</span>.trait = <span class="hljs-string">&quot;strong cool&quot;</span>;
    };

    <span class="hljs-comment">//&#x82F1;&#x96C4;&#x7684;&#x539F;&#x578B;&#x662F;&#x4EBA;</span>
    heroBase.prototype = <span class="hljs-keyword">new</span> human();

    <span class="hljs-comment">//&#x5B9A;&#x4E49;&#x8D85;&#x4EBA;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">superman</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">this</span>.fly = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;superman&quot;</span>);
        };
    };

    <span class="hljs-comment">//&#x8D85;&#x4EBA;&#x7684;&#x539F;&#x578B;&#x5C31;&#x662F;&#x82F1;&#x96C4;</span>
    superman.prototype = <span class="hljs-keyword">new</span> heroBase();

    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">new</span> superman().sexy);<span class="hljs-comment">//male</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">new</span> superman().trait);<span class="hljs-comment">//strong cool</span>
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x6B65;&#x9AA4;&#x5C31;&#x662F;&#xFF1A;</p>
<ul>
<li>&#x8D85;&#x4EBA;&#x7684;&#x6027;&#x522B;&#x662F;&#x795E;&#x9A6C;&#xFF1F;</li>
<li>&#x5149;&#x770B;&#x8D85;&#x4EBA;&#x4E0D;&#x77E5;&#x9053;&#xFF0C;&#x8981;&#x770B;&#x8D85;&#x4EBA;&#x539F;&#x578B;&#xFF1A;&#x82F1;&#x96C4;</li>
<li>&#x770B;&#x82F1;&#x96C4;&#x4E5F;&#x4E0D;&#x77E5;&#x9053;&#xFF0C;&#x8981;&#x770B;&#x82F1;&#x96C4;&#x539F;&#x578B;&#xFF1A;&#x4EBA;</li>
<li>&#x4EBA;&#x7684;sexy&#x5C5E;&#x6027;&#x544A;&#x8BC9;&#x6211;&#x4EEC;&#xFF0C;&#x4ED6;&#x662F;&#x7537;&#x4EBA;</li>
</ul>
<p>&#x597D;&#x5427;&#xFF0C;&#x4E5F;&#x8BB8;&#x4F60;&#x53D1;&#x73B0;&#x4E86;&#xFF0C;&#x4E0A;&#x9762;&#x4F8B;&#x5B50;&#x662F;&#x6709;bug&#x7684;&#xFF0C;&#x8D85;&#x4EBA;&#x662F;&#x5916;&#x661F;&#x4EBA;&#xFF1B;&#x4F46;&#x4F60;&#x80AF;&#x5B9A;&#x53D1;&#x73B0;&#x4E86;&#xFF0C;&#x8FD9;&#x4E0D;&#x5C31;&#x662F;&#x7EE7;&#x627F;&#x5417;&#xFF1F;&#x7EE7;&#x627F;&#x90FD;&#x6709;&#x4E86;&#xFF0C;&#x591A;&#x6001;&#x8FD8;&#x80FD;&#x8FDC;&#x5417;&#xFF1F;</p>
<h3 id="3&#x3001;js&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x539F;&#x578B;&#x6A21;&#x5F0F;&#x5B9E;&#x73B0;&#x7EE7;&#x627F;&#x7684;&#xFF0C;&#x4E14;&#x662F;&#x5355;&#x4E00;&#x7EE7;&#x627F;">3&#x3001;JS&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x539F;&#x578B;&#x6A21;&#x5F0F;&#x5B9E;&#x73B0;&#x7EE7;&#x627F;&#x7684;&#xFF0C;&#x4E14;&#x662F;&#x5355;&#x4E00;&#x7EE7;&#x627F;</h3>
<p>&#x6211;&#x4E2A;&#x4EBA;&#x7684;&#x7406;&#x89E3;&#x662F;&#xFF0C;JS&#x7684;&#x7EE7;&#x627F;&#x8DDF;C#&#x7684;&#x7EE7;&#x627F;&#x867D;&#x7136;&#x5B9E;&#x73B0;&#x5F62;&#x5F0F;&#x4E0D;&#x540C;&#xFF0C;&#x4F46;&#x6709;&#x4E00;&#x70B9;&#x539F;&#x5219;&#x662F;&#x76F8;&#x540C;&#x7684;&#xFF0C;&#x5355;&#x4E00;&#x7EE7;&#x627F;&#x975E;&#x591A;&#x7EE7;&#x627F;&#x3002;&#x5982;&#x4E0A;&#x4F8B;&#x5B50;&#x6362;&#x6210;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#xFF1A;
<code>superman.prototype = new heroBase();</code>
<code>superman.prototype = new human();</code>
&#x6700;&#x7EC8;&#x7ED3;&#x679C;&#x662F;&#xFF0C;&#x8D85;&#x4EBA;&#x7684;&#x539F;&#x578B;&#x9996;&#x5148;&#x5B9A;&#x4E3A;&#x82F1;&#x96C4;&#xFF0C;&#x4F46;&#x53C8;&#x88AB;&#x4EBA;&#x6240;&#x8986;&#x76D6;&#x4E86;&#x3002;&#x7B26;&#x5408;&#x5355;&#x4E00;&#x7EE7;&#x627F;&#x7684;&#x539F;&#x5219;&#x3002;</p>
<h3 id="4&#x3001;&#x7279;&#x522B;&#x8865;&#x5145;&#xFF1A;&#x5173;&#x4E8E;proto&#x4E0E;prototype&#x7684;&#x533A;&#x522B;">4&#x3001;&#x7279;&#x522B;&#x8865;&#x5145;&#xFF1A;&#x5173;&#x4E8E;<code>__proto__</code>&#x4E0E;<code>prototype</code>&#x7684;&#x533A;&#x522B;</h3>
<p>&#x4E4B;&#x524D;&#x4E00;&#x76F4;&#x4EE5;&#x4E3A;&#x641E;&#x61C2;&#x4E86;&#x539F;&#x578B;&#x6A21;&#x5F0F;&#xFF0C;&#x6700;&#x8FD1;&#x770B;&#x5230;&#x4E00;&#x7BC7;&#x5F88;&#x597D;&#x6587;&#x7AE0; [[&#x5B66;&#x4E60;&#x7B14;&#x8BB0;] &#x5C0F;&#x89D2;&#x5EA6;&#x770B;JS&#x539F;&#x578B;&#x94FE; &#x68A6;&#x7985;][1]&#xFF0C;&#x6DA8;&#x59FF;&#x52BF;&#x4E86;&#x3002;</p>
<p>&#x5728; segmentfault &#x4E0A;&#x770B;&#x5230;&#x8FD9;&#x6837;&#x4E00;&#x9053;&#x9898;&#x76EE;&#xFF1A;</p>
<pre><code>var F = function(){};
Object.prototype.a = function(){};
Function.prototype.b = function(){};
var f = new F();
</code></pre><p>&#x95EE;&#xFF1A;f &#x80FD;&#x53D6;&#x5230;a,b&#x5417;&#xFF1F;&#x539F;&#x7406;&#x662F;&#x4EC0;&#x4E48;&#xFF1F;</p>
<p>&#x5173;&#x952E;&#x7406;&#x89E3;&#xFF1A;
<code>prototype</code>&#x662F;&#x5BF9;&#x8C61;&#x539F;&#x578B;
<code>__proto__</code>&#x662F;&#x5BF9;&#x8C61;&#x6784;&#x9020;&#x5668;&#x7684;&#x539F;&#x578B;
&#x5173;&#x4E8E;&#x4E24;&#x8005;&#x533A;&#x522B;&#xFF0C;&#x63A8;&#x8350;&#x4E00;&#x904D;&#x535A;&#x6587;&#xFF0C;&#x89E3;&#x91CA;&#x975E;&#x5E38;&#x8BE6;&#x7EC6;&#xFF0C;[&#x7406;&#x89E3;js&#x4E2D;&#x7684;&#x539F;&#x578B;&#x94FE;&#xFF0C;prototype&#x4E0E;<strong>proto</strong>&#x7684;&#x5173;&#x7CFB;][2]</p>
<p>&#x81EA;&#x5DF1;&#x5217;&#x4E86;&#x4F8B;&#x5B50;&#xFF0C;&#x5E94;&#x8BE5;&#x6BD4;&#x8F83;&#x5BB9;&#x6613;&#x7406;&#x89E3;</p>
<pre><code>    var F = function () { };
    Object.prototype.a = function () {
        console.log(&quot;a&quot;);
    };
    Function.prototype.b = function () {
        console.log(&quot;b&quot;);
    };
    var f = new F();

    //&#x6CE8;&#x610F;&#xFF1A;&#x5BF9;&#x8C61;&#x7684;__proto__&#x5C5E;&#x6027;&#xFF0C;&#x6307;&#x5411;&#x5BF9;&#x8C61;&#x7684;&#x7236;&#x7EA7;&#x6784;&#x9020;&#x5668;&#x7684;prototype&#x539F;&#x578B;

    console.log(f);

    console.log(f.__proto__);                         //F.prototype
    console.log(F.prototype.__proto__);               //Ojbect.prototype
    console.log(Object.prototype.a());                //a

    console.log(f.__proto__.__proto__.a());           //a

    /****************************************************************/

    console.log(f.constructor);                       //F
    console.log(F.__proto__);                         //Function.prototype
    console.log(Function.prototype.b());              //b

    console.log(f.constructor.__proto__.b());         //b

    //&#x7ED3;&#x8BBA;&#xFF1A;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x7684;__proto__&#x90FD;&#x6307;&#x5411;&#x5176;&#x6784;&#x9020;&#x5668;&#x7684;prototype
    //&#x7ED3;&#x8BBA;&#xFF1A;&#x6240;&#x6709;&#x6784;&#x9020;&#x5668;/&#x51FD;&#x6570;&#x7684;__proto__&#x90FD;&#x6307;&#x5411;Function.prototype&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x7A7A;&#x51FD;&#x6570;&#xFF08;Empty function&#xFF09;
    //&#x7ED3;&#x8BBA;&#xFF1A;Function.prototype&#x7684;__proto__&#x6700;&#x7EC8;&#x6307;&#x5411;Object.prototype
</code></pre><ol>
<li>&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x7684;<strong>proto</strong>&#x90FD;&#x6307;&#x5411;&#x5176;&#x6784;&#x9020;&#x5668;&#x7684;prototype</li>
<li>&#x6240;&#x6709;&#x6784;&#x9020;&#x5668;/&#x51FD;&#x6570;&#x7684;<strong>proto</strong>&#x90FD;&#x6307;&#x5411;Function.prototype&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x7A7A;&#x51FD;&#x6570;&#xFF08;Empty function&#xFF09;</li>
<li>Function.prototype&#x7684;<strong>proto</strong>&#x6700;&#x7EC8;&#x6307;&#x5411;Object.prototype</li>
</ol>
<h2 id="&#x591A;&#x6001;">&#x591A;&#x6001;</h2>
<p>JS&#x7684;&#x591A;&#x6001;&#x662F;&#x901A;&#x8FC7;&#x4E24;&#x70B9;&#x5B9E;&#x73B0;&#x7684;&#xFF1A;1&#x3001;&#x539F;&#x578B;&#x6A21;&#x5F0F;&#x5B9E;&#x73B0;&#x7EE7;&#x627F;&#xFF1B;2&#x3001;&#x52A8;&#x6001;&#x7C7B;&#x578B;&#x5B9E;&#x73B0;&#x6CDB;&#x578B;</p>
<p>&#x56DE;&#x60F3;&#x4E00;&#x4E0B;&#xFF0C;&#x6211;&#x4EEC;&#x521A;&#x5B66;&#x4E60;C#&#x7684;&#x90A3;&#x4E2A;&#x7ECF;&#x5178;&#x4F8B;&#x5B50;</p>
<pre><code>    public class Hero
    {
        public virtual void Fly()
        {
            Console.WriteLine(&quot;hero fly&quot;);
        }
    }

    public class SuperMan : Hero
    {
        public override void Fly()
        {
            base.Fly();
            Console.WriteLine(&quot;SuperMan fly&quot;);
        }
    }

    public class IronMan : Hero
    {
        public override void Fly()
        {
            base.Fly();
            Console.WriteLine(&quot;IronMan fly&quot;);
        }
    }

    public class Main
    {
        public void MainFunction()
        {
            LetsFly(new SuperMan());
            LetsFly(new IronMan());
        }

        public void LetsFly(Hero hero)
        {
            hero.Fly();
        }
    }
</code></pre><p>&#x518D;&#x6765;&#x770B;&#x770B;JS&#x7684;&#x5B9E;&#x73B0;</p>
<pre><code class="lang-javascript">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">superman</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">this</span>.fly = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;superman fly&quot;</span>);
        };
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bird</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">this</span>.fly = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;bird fly&quot;</span>);
        };
    };

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">letsFly</span>(<span class="hljs-params">hero</span>) </span>{
        hero.fly();
    }

    <span class="hljs-keyword">var</span> sm = <span class="hljs-keyword">new</span> superman();
    <span class="hljs-keyword">var</span> b = <span class="hljs-keyword">new</span> bird();
    letsFly(sm);<span class="hljs-comment">//superman fly</span>
    letsFly(b);<span class="hljs-comment">//bird fly;</span>
</code></pre>
<p>LetsFly()&#x65B9;&#x6CD5;&#xFF0C;C#&#x8DDF;JS&#x63A5;&#x53D7;&#x7684;&#x540C;&#x6837;&#x90FD;&#x662F;Hero&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;</p>
<p>&#x5BF9;&#x4E8E;C#&#x800C;&#x8A00;&#xFF0C;LetsFly&#x65B9;&#x6CD5;&#x8981;&#x6C42;&#x4E0D;&#x7BA1;&#x662F;&#x795E;&#x9A6C;Hero&#xFF0C;<strong>&#x53EA;&#x8981;&#x5B9E;&#x73B0;&#x4E86;&#x57FA;&#x7C7B;Hero&#x7684;Fly</strong>&#xFF0C;&#x5B83;&#x5C31;&#x80FD;&#x6267;&#x884C;LetsFly&#x65B9;&#x6CD5;&#xFF0C;&#x4EE5;&#x540E;&#x5373;&#x4F7F;&#x6709;&#x518D;&#x591A;&#x7684;&#x82F1;&#x96C4;&#xFF0C;&#x7EE7;&#x627F;Hero&#x5373;&#x53EF;&#x3002;</p>
<p>&#x800C;JS&#xFF0C;LetsFly&#x65B9;&#x6CD5;&#x8981;&#x6C42;&#x4E0D;&#x7BA1;&#x662F;&#x795E;&#x9A6C;&#x5BF9;&#x8C61;&#xFF0C;<strong>&#x53EA;&#x8981;&#x6709;Fly&#x65B9;&#x6CD5;</strong>&#xFF0C;&#x5B83;&#x5C31;&#x80FD;&#x6267;&#x884C;LetsFly&#x65B9;&#x6CD5;&#xFF0C;&#x4EE5;&#x540E;&#x5373;&#x4F7F;&#x6709;&#x518D;&#x591A;&#x7684;&#x82F1;&#x96C4;&#xFF0C;&#x82F1;&#x96C4;&#x4F1A;Fly&#x5373;&#x53EF;&#x3002;</p>
<p>&#x5BF9;&#x6BD4;&#x4E4B;&#x4E0B;&#xFF0C;&#x4F18;&#x7F3A;&#x70B9;&#x662F;&#x663E;&#x800C;&#x6613;&#x89C1;&#x7684;&#xFF0C;&#x524D;&#x8005;&#x53D7;&#x5230;&#x675F;&#x7F1A;&#xFF0C;&#x5C24;&#x5176;&#x5728;&#x590D;&#x6742;&#x7C7B;&#x578B;&#x4E4B;&#x95F4;&#x7EE7;&#x627F;&#x4E0E;&#x5F15;&#x7528;&#x63D0;&#x73B0;&#x7684;&#x66F4;&#x52A0;&#x51F8;&#x663E;&#xFF0C;&#x4F46;&#x7C7B;&#x578B;&#x5B89;&#x5168;&#x6027;&#x9AD8;&#xFF1B;</p>
<p>&#x540E;&#x8005;&#x65E0;&#x62D8;&#x65E0;&#x675F;&#xFF0C;&#x4F46;&#x7C7B;&#x578B;&#x5B89;&#x5168;&#x6027;&#x4F4E;&#xFF0C;&#x5982;&#x4E0A;&#x4F8B;&#x5B50;&#xFF0C;LetsFly&#x4F20;&#x5165;&#x7684;&#x53EF;&#x80FD;&#x4E0D;&#x662F;Hero&#xFF0C;&#x5F88;&#x53EF;&#x80FD;&#x662F;Bird&#x3002;</p>
<h2 id="&#x95ED;&#x5305;&#x4E0E;&#x9AD8;&#x9636;&#x51FD;&#x6570;">&#x95ED;&#x5305;&#x4E0E;&#x9AD8;&#x9636;&#x51FD;&#x6570;</h2>
<p>&#x5173;&#x4E8E;&#x95ED;&#x5305;&#x201C;closure&#x201D;&#xFF0C;&#x521A;&#x5F00;&#x59CB;&#x63A5;&#x89E6;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x767E;&#x5EA6;&#x4E86;N&#x904D;&#x76F8;&#x5173;&#x6559;&#x7A0B;&#x8FD8;&#x662F;&#x770B;&#x5F97;&#x6211;&#x4E00;&#x5934;&#x96FE;&#x6C34;&#xFF0C;
&#x542C;&#x8BF4;&#x8FD8;&#x4F1A;&#x6709;&#x5185;&#x5B58;&#x6CC4;&#x9732;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x597D;&#x5427;&#xFF0C;&#x5728;&#x5F00;&#x53D1;&#x4E2D;&#x5E72;&#x8106;&#x5C31;&#x4E0D;&#x7528;&#x5427;&#x3002;&#x76F4;&#x5230;&#x6709;&#x4E00;&#x5929;&#xFF0C;&#x5076;&#x5C14;&#x770B;&#x5230;<strong>&#x9AD8;&#x9636;&#x51FD;&#x6570;</strong>&#xFF0C;&#x5BF9;&#x4E8E;&#x95ED;&#x5305;&#x4EE5;&#x53CA;&#x6574;&#x4E2A;JS&#x8BED;&#x8A00;&#x7684;&#x7406;&#x89E3;&#x53EF;&#x4EE5;&#x8BF4;&#x4EA7;&#x751F;&#x4E86;&#x7FFB;&#x5929;&#x8986;&#x5730;&#x7684;&#x53D8;&#x5316;&#x3002;</p>
<p>&#x5728;&#x8FD9;&#x4E4B;&#x524D;&#xFF0C;&#x5148;&#x7ED9;&#x5927;&#x5BB6;&#x56DE;&#x987E;&#x4E00;&#x4E0B;&#xFF0C;&#x95ED;&#x5305;&#x4E4B;&#x6240;&#x4EE5;&#x6210;&#x4E3A;&#x95ED;&#x5305;&#x4E4B;&#x524D;&#xFF0C;&#x6709;&#x4E00;&#x4E2A;&#x5F88;&#x91CD;&#x8981;&#x7684;&#x524D;&#x63D0;&#x6982;&#x5FF5;&#xFF1A;&#x53D8;&#x91CF;&#x7684;&#x751F;&#x547D;&#x5468;&#x671F;&#x3002;
&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#xFF0C;var&#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x53D8;&#x91CF;&#x5C5E;&#x4E8E;&#x51FD;&#x6570;&#x5185;&#xFF0C;&#x51FD;&#x6570;&#x5916;&#x65E0;&#x6CD5;&#x8BBF;&#x95EE;&#xFF1B;&#x53CD;&#x4E4B;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x5B9A;&#x4E49;var&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x50CF;<code>x=12</code>&#xFF0C;x&#x5C5E;&#x4E8E;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;
&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x7684;&#x751F;&#x547D;&#x5468;&#x671F;&#x662F;&#x6C38;&#x4E45;&#x7684;&#xFF0C;&#x7531;&#x9875;&#x9762;&#x52A0;&#x8F7D;&#x5230;&#x5173;&#x95ED;&#xFF1B;&#x800C;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x4ECE;&#x51FD;&#x6570;&#x6267;&#x884C;&#x5230;&#x7ED3;&#x675F;&#xFF0C;GC&#x68C0;&#x6D4B;&#x5230;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#x6CA1;&#x6709;&#x518D;&#x88AB;&#x4F7F;&#x7528;&#x5219;&#x4F1A;&#x9500;&#x6BC1;&#x5B83;&#x3002;</p>
<pre><code class="lang-javascript">    <span class="hljs-keyword">var</span> fn = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">var</span> a = <span class="hljs-string">&quot;a&quot;</span>;
        b = <span class="hljs-string">&quot;b&quot;</span>;

        <span class="hljs-keyword">var</span> fni = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            c = <span class="hljs-string">&quot;c&quot;</span>;
        }();
    }();

    <span class="hljs-comment">//console.log(a);//a is not defined</span>
    <span class="hljs-built_in">console</span>.log(b);<span class="hljs-comment">//b</span>
    <span class="hljs-built_in">console</span>.log(c);<span class="hljs-comment">//c</span>
</code></pre>
<p>&#x5173;&#x952E;&#x5C31;&#x5728;&#x8FD9;&#xFF0C;&#x5982;&#x679C;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#x5728;&#x51FD;&#x6570;&#x6267;&#x884C;&#x7ED3;&#x675F;&#x540E;&#xFF0C;&#x4ECD;&#x7136;&#x6709;&#x88AB;&#x4F7F;&#x7528;&#x5462;&#xFF1F;</p>
<p>&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x5C31;&#x662F;&#x2014;&#x2014;<strong>&#x9AD8;&#x9636;&#x51FD;&#x6570;</strong>&#x3002;</p>
<p>&#x9AD8;&#x9636;&#x51FD;&#x6570;&#x540D;&#x5B57;&#x770B;&#x8D77;&#x6765;&#x9AD8;&#x7AEF;&#xFF0C;&#x5B9E;&#x9645;&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x6EE1;&#x8DB3;&#x4EE5;&#x4E0B;&#x6761;&#x4EF6;&#x5176;&#x4E00;&#x5C31;&#x662F;&#x9AD8;&#x9636;&#x51FD;&#x6570;&#xFF1A;</p>
<p>1&#x3001;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x662F;&#x51FD;&#x6570;&#xFF1B;</p>
<p>2&#x3001;&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x662F;&#x51FD;&#x6570;&#xFF1B;</p>
<pre><code class="lang-javascript">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">myFunction</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x6211;&#x662F;&#x4E2A;&#x51FD;&#x6570;&quot;</span>);
    };
    <span class="hljs-comment">//&#x9AD8;&#x9636;&#x51FD;&#x6570;1&#x2014;&#x2014;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x662F;&#x51FD;&#x6570;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fnHO1</span>(<span class="hljs-params">fn</span>) </span>{
        fn();
    }
    <span class="hljs-comment">//&#x9AD8;&#x9636;&#x51FD;&#x6570;2&#x2014;&#x2014;&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x662F;&#x51FD;&#x6570;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fnHO2</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">return</span> myFunction;
    };

    <span class="hljs-comment">//&#x8C03;&#x7528;&#x9AD8;&#x9636;&#x51FD;&#x6570;1</span>
    fnHO1(myFunction);<span class="hljs-comment">//&#x6211;&#x662F;&#x4E2A;&#x51FD;&#x6570;</span>

    <span class="hljs-comment">//&#x8C03;&#x7528;&#x9AD8;&#x9636;&#x51FD;&#x6570;2</span>
    fnHO2();<span class="hljs-comment">//&#x795E;&#x9A6C;&#x90FD;&#x6CA1;&#x6709;&#x53D1;&#x751F;</span>

    <span class="hljs-comment">//&#x8C03;&#x7528;&#x9AD8;&#x9636;&#x51FD;&#x6570;2&#xFF0C;&#x83B7;&#x5F97;&#x7684;&#x662F;&#x5B83;&#x7684;&#x5185;&#x90E8;&#x51FD;&#x6570;&#x4F53;</span>
    <span class="hljs-keyword">var</span> f2 = fnHO2();
    <span class="hljs-comment">//&#x518D;&#x6267;&#x884C;&#xFF0C;&#x624D;&#x662F;&#x8C03;&#x7528;&#x5B83;&#x7684;&#x5185;&#x90E8;&#x51FD;&#x6570;</span>
    f2();<span class="hljs-comment">//&#x6211;&#x662F;&#x4E2A;&#x51FD;&#x6570;</span>
</code></pre>
<p>&#x5728;&#x9AD8;&#x9636;&#x51FD;&#x6570;&#x7684;&#x57FA;&#x7840;&#xFF0C;&#x6211;&#x4EEC;&#x6765;&#x770B;&#x770B;&#xFF0C;&#x53F2;&#x4E0A;&#x6700;&#x7ECF;&#x5178;&#x7684;&#x95ED;&#x5305;&#x5B9E;&#x4F8B;&#x3002;</p>
<pre><code class="lang-javascript">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add_outer</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">var</span> i = <span class="hljs-number">1</span>;

        <span class="hljs-comment">//&#x8FD4;&#x56DE;&#x503C;&#x662F;&#x5185;&#x90E8;&#x51FD;&#x6570;&#xFF0C;inner&#x8C03;&#x7528;&#x4E86;&#x5176;&#x5916;&#x90E8;&#x7684;&#x53D8;&#x91CF;</span>
        <span class="hljs-comment">//&#x6240;&#x4EE5;inner&#x6267;&#x884C;&#x7ED3;&#x675F;&#x65F6;&#xFF0C;i&#x6CA1;&#x6709;&#x88AB;&#x9500;&#x6BC1;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">inner</span>(<span class="hljs-params"></span>) </span>{
            i++;
            <span class="hljs-keyword">return</span> i;
        };
    };

    <span class="hljs-comment">//&#x6267;&#x884C;add_outer&#x83B7;&#x53D6;&#x7684;&#x662F;&#x5B83;&#x7684;&#x5185;&#x90E8;&#x51FD;&#x6570;&#x4F53;inner&#xFF0C;&#x4F46;&#x6CA1;&#x6709;&#x6267;&#x884C;</span>
    <span class="hljs-keyword">var</span> inner = add_outer();

    <span class="hljs-comment">//&#x771F;&#x6B63;&#x6267;&#x884C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x53D8;&#x91CF;i&#x6CA1;&#x6709;&#x88AB;&#x9500;&#x6BC1;&#xFF0C;&#x5F62;&#x6210;&#x9012;&#x589E;</span>
    <span class="hljs-built_in">console</span>.log(inner());<span class="hljs-comment">//2</span>
    <span class="hljs-built_in">console</span>.log(inner());<span class="hljs-comment">//3</span>
    <span class="hljs-built_in">console</span>.log(inner());<span class="hljs-comment">//4</span>
</code></pre>
<p>&#x6211;&#x5BF9;&#x4E8E;&#x95ED;&#x5305;&#x7684;&#x7406;&#x89E3;&#x5F88;&#x7B80;&#x5355;&#xFF1A;==&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x503C;&#x662F;&#x4E2A;&#x5185;&#x90E8;&#x51FD;&#x6570;&#xFF0C;&#x5185;&#x90E8;&#x8C03;&#x7528;&#x4E86;&#x51FD;&#x6570;&#x7684;&#x5185;&#x90E8;&#x53D8;&#x91CF;==&#x3002;</p>
<p>&#x4E24;&#x4E2A;&#x6761;&#x4EF6;&#xFF0C;&#x7F3A;&#x4E00;&#x4E0D;&#x53EF;&#x3002;&#x5982;&#x679C;&#x5C06;&#x4EE5;&#x4E0A;&#x4F8B;&#x5B50;&#x6539;&#x4E00;&#x4E0B;&#xFF0C;&#x5185;&#x90E8;&#x6709;&#x51FD;&#x6570;&#xFF0C;&#x4F46;&#x4E0D;&#x662F;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x5C31;&#x4E0D;&#x662F;&#x95ED;&#x5305;&#x4E86;&#x3002;</p>
<pre><code class="lang-javascript">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add_outer</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">var</span> i = <span class="hljs-number">1</span>;

        <span class="hljs-comment">//&#x8FD4;&#x56DE;&#x503C;&#x4E0D;&#x662F;&#x51FD;&#x6570;&#xFF0C;&#x5F62;&#x6210;&#x4E0D;&#x4E86;&#x95ED;&#x5305;</span>
        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">inner</span>(<span class="hljs-params"></span>) </span>{
            i++;
            <span class="hljs-built_in">console</span>.log(i);
        };
        inner();
    };

    <span class="hljs-comment">//&#x6267;&#x884C;&#x591A;&#x6B21;&#xFF0C;&#x503C;&#x4E5F;&#x4E0D;&#x4F1A;&#x53D8;</span>
    add_outer();<span class="hljs-comment">//2</span>
    add_outer();<span class="hljs-comment">//2</span>
</code></pre>
<p>&#x4E5F;&#x8BB8;&#x5927;&#x5BB6;&#x4F1A;&#x7591;&#x95EE;&#xFF0C;&#x65E2;&#x7136;&#x5185;&#x90E8;&#x53D8;&#x91CF;i&#x5728;&#x51FD;&#x6570;&#x7ED3;&#x675F;&#x540E;&#x4ECD;&#x7136;&#x4F7F;&#x7528;&#xFF0C;&#x5BFC;&#x81F4;GC&#x65E0;&#x6CD5;&#x56DE;&#x6536;&#x5176;&#x5185;&#x5B58;&#xFF0C;&#x90A3;&#x4E0D;&#x5C31;&#x662F;&#x5185;&#x5B58;&#x6CC4;&#x9732;&#x5417;&#xFF1F;
&#x662F;&#x7684;&#x3002;&#x5176;&#x5B9E;&#x6211;&#x4EEC;&#x53CD;&#x8FC7;&#x6765;&#x60F3;&#xFF0C;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x4E0D;&#x4F7F;&#x7528;&#x95ED;&#x5305;&#x7684;&#x65B9;&#x5F0F;&#x5B9E;&#x73B0;&#x4EE5;&#x4E0A;&#x7D2F;&#x52A0;&#x7684;&#x4F8B;&#x5B50;&#xFF0C;&#x6539;&#x4E3A;&#x4F7F;&#x7528;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x5B58;&#x653E;&#x53D8;&#x91CF;<code>i</code>&#xFF0C;&#x5168;&#x5C40;&#x53D8;&#x91CF;<code>i</code>&#x662F;&#x5426;&#x540C;&#x6837;&#x4E5F;&#x662F;&#x4E0D;&#x80FD;&#x88AB;&#x56DE;&#x6536;&#x5462;&#xFF1F;&#xFF01;</p>
<pre><code class="lang-javascript">    <span class="hljs-comment">//function add_outer() {</span>
        <span class="hljs-keyword">var</span> i = <span class="hljs-number">1</span>;

        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">inner</span>(<span class="hljs-params"></span>) </span>{
            i++;
            <span class="hljs-keyword">return</span> i;
        };
    <span class="hljs-comment">//};</span>

    <span class="hljs-comment">////&#x6267;&#x884C;add_outer&#x83B7;&#x53D6;&#x7684;&#x662F;&#x5B83;&#x7684;&#x5185;&#x90E8;&#x51FD;&#x6570;&#x4F53;inner&#xFF0C;&#x4F46;&#x6CA1;&#x6709;&#x6267;&#x884C;</span>
    <span class="hljs-comment">//var inner = add_outer();</span>

    <span class="hljs-comment">//&#x771F;&#x6B63;&#x6267;&#x884C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x53D8;&#x91CF;i&#x6CA1;&#x6709;&#x88AB;&#x9500;&#x6BC1;&#xFF0C;&#x5F62;&#x6210;&#x9012;&#x589E;</span>
    <span class="hljs-built_in">console</span>.log(inner());<span class="hljs-comment">//2</span>
    <span class="hljs-built_in">console</span>.log(inner());<span class="hljs-comment">//3</span>
    <span class="hljs-built_in">console</span>.log(inner());<span class="hljs-comment">//4</span>
</code></pre>
<p>&#x56E0;&#x6B64;&#xFF0C;&#x95ED;&#x5305;&#x4E0E;&#x9AD8;&#x9636;&#x51FD;&#x6570;&#xFF0C;&#x53EA;&#x662F;&#x51FD;&#x6570;&#x5F0F;&#x7F16;&#x7A0B;&#x7684;&#x7F16;&#x5199;&#x65B9;&#x5F0F;&#xFF0C;&#x5373;&#x4F7F;&#x5E76;&#x4E0D;&#x662F;&#x9020;&#x6210;&#x5185;&#x5B58;&#x6CC4;&#x9732;&#x7684;&#x539F;&#x56E0;&#x3002;&#x5173;&#x4E8E;&#x95ED;&#x5305;&#x4E0E;&#x5185;&#x5B58;&#x6CC4;&#x9732;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x8BF7;&#x79FB;&#x6B65; <a href="http://www.cnblogs.com/yakun/p/3932026.html" target="_blank">http://www.cnblogs.com/yakun/p/3932026.html</a></p>
<p>&#x539F;&#x578B;&#x6A21;&#x5F0F;&#x3001;&#x95ED;&#x5305;&#x4E0E;&#x9AD8;&#x9636;&#x51FD;&#x6570;&#x5E94;&#x8BE5;&#x53EF;&#x4EE5;&#x8BF4;&#x662F;JS&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x7684;&#x57FA;&#x7840;&#x8981;&#x9886;&#x5427;&#x3002;&#x5728;&#x4E0B;&#x4E00;&#x7AE0;&#xFF0C;&#x518D;&#x5206;&#x4EAB;&#x4E00;&#x4E0B;JS&#x7684;&#x51E0;&#x79CD;&#x5E38;&#x7528;&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x3002;</p>
<p>&#x8FD8;&#x662F;&#x50CF;&#x524D;&#x9762;&#x6240;&#x8BF4;&#x7684;&#xFF0C;&#x6709;&#x4EC0;&#x4E48;&#x5730;&#x65B9;&#x8BF4;&#x9519;&#xFF0C;&#x671B;&#x5927;&#x5BB6;&#x6307;&#x6B63;&#x3002;</p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; tgor.top 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-04-23 15:32:53
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../category/前端技术栈.html" class="navigation navigation-prev " aria-label="Previous page: 前端技术栈">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="html相对路径与绝对路径.html" class="navigation navigation-next " aria-label="Next page: Html相对路径与绝对路径">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"JavaScript设计模式","level":"1.14.1","depth":2,"next":{"title":"Html相对路径与绝对路径","level":"1.14.2","depth":2,"path":"前端/html相对路径与绝对路径.md","ref":"前端/html相对路径与绝对路径.md","articles":[]},"previous":{"title":"前端技术栈","level":"1.14","depth":1,"path":"category/前端技术栈.md","ref":"category/前端技术栈.md","articles":[{"title":"JavaScript设计模式","level":"1.14.1","depth":2,"path":"前端/JavaScript设计模式.md","ref":"前端/JavaScript设计模式.md","articles":[]},{"title":"Html相对路径与绝对路径","level":"1.14.2","depth":2,"path":"前端/html相对路径与绝对路径.md","ref":"前端/html相对路径与绝对路径.md","articles":[]},{"title":"微信小程序学习笔记","level":"1.14.3","depth":2,"path":"前端/微信小程序学习笔记.md","ref":"前端/微信小程序学习笔记.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["chapter-fold","splitter","tbfed-pagefooter","page-toc-button","-search","search-pro","popup","back-to-top-button","code","copy-code-button"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy tgor.top 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"sepia","family":"serif","size":1},"highlight":{},"page-toc-button":{"maxTocDepth":2,"minTocSize":2},"back-to-top-button":{},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tgor","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"tgor note","gitbook":"*","description":"tgor生活工作记录"},"file":{"path":"前端/JavaScript设计模式.md","mtime":"2020-04-23T07:32:53.378Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-29T08:43:24.127Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

